package com.gitee.wsl.coroutines.job

import com.gitee.wsl.api.Key
import com.gitee.wsl.api.StringMatcher
import com.gitee.wsl.coroutines.job.trigger.TriggerKey


class GroupMatcher<T : Key<T>> protected constructor(
     sCompareTo: String,
     eCompareWith: EStringOperatorName,
) : StringMatcher<T>(sCompareTo, eCompareWith) {
    
    override fun getValue(key: T): String {
        return key.group?:""
    }

    companion object {
        /**
         * Create a GroupMatcher that matches groups equaling the given string.
         */
        fun <T : Key<T>> groupEquals(sCompareTo: String): GroupMatcher<T> {
            return GroupMatcher(sCompareTo, EStringOperatorName.EQUALS)
        }

        /**
         * Create a GroupMatcher that matches job groups equaling the given string.
         */
        fun jobGroupEquals(sCompareTo: String): GroupMatcher<JobKey> {
            return groupEquals(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches trigger groups equaling the given
         * string.
         */
        fun triggerGroupEquals(sCompareTo: String): GroupMatcher<TriggerKey> {
            return groupEquals(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches groups starting with the given string.
         */
        fun <T : Key<T>> groupStartsWith(sCompareTo: String): GroupMatcher<T> {
            return GroupMatcher(sCompareTo, EStringOperatorName.STARTS_WITH)
        }

        /**
         * Create a GroupMatcher that matches job groups starting with the given
         * string.
         */
        fun jobGroupStartsWith(sCompareTo: String): GroupMatcher<JobKey> {
            return groupStartsWith(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches trigger groups starting with the given
         * string.
         */
        fun triggerGroupStartsWith(sCompareTo: String): GroupMatcher<TriggerKey> {
            return groupStartsWith(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches groups ending with the given string.
         */
        fun <T : Key<T>> groupEndsWith(sCompareTo: String): GroupMatcher<T> {
            return GroupMatcher(sCompareTo, EStringOperatorName.ENDS_WITH)
        }

        /**
         * Create a GroupMatcher that matches job groups ending with the given string.
         */
        fun jobGroupEndsWith(sCompareTo: String): GroupMatcher<JobKey> {
            return groupEndsWith(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches trigger groups ending with the given
         * string.
         */
        fun triggerGroupEndsWith(sCompareTo: String): GroupMatcher<TriggerKey> {
            return groupEndsWith(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches groups containing the given string.
         */
        fun <T : Key<T>> groupContains(sCompareTo: String): GroupMatcher<T> {
            return GroupMatcher(sCompareTo, EStringOperatorName.CONTAINS)
        }

        /**
         * Create a GroupMatcher that matches job groups containing the given string.
         */
        fun jobGroupContains(sCompareTo: String): GroupMatcher<JobKey> {
            return groupContains(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches trigger groups containing the given
         * string.
         */
        fun triggerGroupContains(sCompareTo: String): GroupMatcher<TriggerKey> {
            return groupContains(sCompareTo)
        }

        /**
         * Create a GroupMatcher that matches groups starting with the given string.
         */
        fun <T : Key<T>> anyGroup(): GroupMatcher<T> {
            return GroupMatcher("", EStringOperatorName.ANYTHING)
        }

        /**
         * Create a GroupMatcher that matches job groups starting with the given
         * string.
         */
        fun anyJobGroup(): GroupMatcher<JobKey> {
            return anyGroup()
        }

        /**
         * Create a GroupMatcher that matches trigger groups starting with the given
         * string.
         */
        fun anyTriggerGroup(): GroupMatcher<TriggerKey> {
            return anyGroup()
        }
    }
}
